<?php

namespace App\Rules\Admin;

use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Auth;

class IsOldPasswordVaildRule implements Rule
{
    private $admin_id;

    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct($admin_id = 0)
    {
        $this->admin_id = $admin_id ?: auth('admin')->id();
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return Auth::guard('admin')->attempt([
            'id'       => $this->admin_id,
            'password' => $value,
        ]);
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return '旧密码不正确';
    }
}
